﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WAContratos;
using WAContratos.Manager;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

namespace WebContratos
{
    public partial class consuXmlPagos : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            /* String codigoUsuario = Request.QueryString["codigoUsuario"].ToString();

         codigoUsuario = General.nvl(codigoUsuario, "");*/

            String codigo_contrato = Request.QueryString["codigoContrato"].ToString();

            codigo_contrato = General.nvl(codigo_contrato, "");

            System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
            response.Buffer = true;
            response.ClearContent();
            response.ClearHeaders();
            response.ContentType = "text/xml";

            OracleConnection conn = Conexion.Cone;
            OracleCommand cm = new OracleCommand();
            OracleDataReader oReader;
            String sql = "select codigo_contrato, secuencia_anticipo, to_char(fecha_entrega,'rrrr-mm-dd') fecha_Entrega, porcentaje, informe_anticipo, forma_pago, poliza_asociada from T_ANTICIPO where codigo_contrato = '" + codigo_contrato + "'";



            conn.Open();
            cm.Connection = conn;
            cm.CommandText = sql;


            oReader = cm.ExecuteReader();
            //int valId = 0;


            response.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            response.Write("<rows id=\"0\">");
            response.Write("<head>");
            response.Write("<column width=\"82\" type=\"link\"  align=\"right\" sort=\"str\">Secuencia de Pago</column>");
            response.Write("<column width=\"150\" type=\"ro\" format=\"%Y-%m-%d\" align=\"center\" sort=\"date\">Fecha de Entrega</column>");
            response.Write("<column width=\"250\" type=\"ro\"  align=\"right\" sort=\"str\">Porcentaje</column>");
            response.Write("<column width=\"250\" type=\"ro\"  align=\"left\" sort=\"str\">Informe de Anticipo</column>");
            response.Write("<column width=\"250\" type=\"ro\"  align=\"left\" sort=\"str\">Forma de Pago</column>");
            response.Write("<column width=\"250\" type=\"ro\"  align=\"left\" sort=\"str\">Poliza Asociada</column>");
            response.Write("<settings><colwidth>px</colwidth></settings></head>");


            string txtTipoGarantia = "";
            ContratoManager unContra = new ContratoManager();
            string txtEstaGarantia = "";
            string txtFormaPago = "";
            string urls = "";

            Session.Add("codContrato", codigo_contrato);

            //------------------------------------------------------------------------           
            while (oReader.Read())
            {
                //response.Write(xmldata);
                //txtTipoGarantia = 
                //javascript:alert(1);
               
                /*txtTipoGarantia = unContra.obtieneDescrip(General.nvl(oReader.GetValue(2).ToString(), ""), "TIPGARAN");
                txtEstaGarantia = unContra.obtieneDescrip(General.nvl(oReader.GetValue(8).ToString(), ""), "ESTGARAN");*/
                txtFormaPago = unContra.obtieneDescrip(General.nvl(oReader.GetValue(5).ToString(), ""), "FORMPAGO");
                urls = "^javascript:openVentana(\"consultaPagos.aspx?codPagos=" + General.nvl(oReader.GetValue(1).ToString(), "") + "\");^_self";

                response.Write("<row id=\"" + oReader.GetValue(1).ToString() + "\">");
                response.Write("<cell>" + General.nvl(oReader.GetValue(1).ToString(), "") + urls + "</cell>");
                response.Write("<cell><![CDATA[" + General.nvl(oReader.GetValue(2).ToString(), "") + "]]></cell>");
                response.Write("<cell><![CDATA[" + General.nvl(oReader.GetValue(3).ToString(), "") + "]]></cell>");
                response.Write("<cell><![CDATA[" + General.nvl(oReader.GetValue(4).ToString(), "") + "]]></cell>");
                response.Write("<cell><![CDATA[" + txtFormaPago + "]]></cell>");
                response.Write("<cell><![CDATA[" + General.nvl(oReader.GetValue(6).ToString(), "") + "]]></cell>");                
                response.Write("</row>");



            }

            cm.Dispose();
            conn.Close();
            GC.Collect();

            response.Write("</rows>");

            response.End();   //Stop all other output to the browser

        }
    }
}
